<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>后台系统管理</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script th:src="@{/webjars/jquery/3.5.1/jquery.min.js}"></script>
    <script th:src="@{/common/common.js}"></script>
</head>
<body class="login-bg" style="background-position:center; background-repeat:no-repeat;background-image: url('/images/bgi.jpg')">

<div class="login">
    <div class="message">登录管理</div>
    <div id="darkbannerwrap"></div>

    <form method="post" class="layui-form" id="login">
        <input id="username" placeholder="用户名" value="123123" type="text" lay-verify="required" class="layui-input">
        <hr class="hr15">
        <input id="password" lay-verify="required" value="123456" placeholder="密码" type="password" class="layui-input">
        <hr class="hr20">
        <div class="layui-form-item">
            <label class="layui-form-label">登录人员</label>
            <div class="layui-input-block">
                <input type="radio" name="member" class="member" value="管理员" title="管理员" >
                <input type="radio" name="member" class="member" value="售货员" title="售货员" checked>
            </div>
        </div>
        <hr class="hr20">
        <input value="登录" lay-submit lay-filter="login" style="width:100%;" id="btn" type="button">
        <hr class="hr20">
    </form>
</div>
<script>
    $(document).keyup(function (event) {
        if (event.keyCode === 13) {
            $("#btn").click();
        }
    });
    $(function () {
        $("#btn").click(function () {
            var username = $("#username").val();
            var password = $("#password").val();
            var member = $('input[name=member]:checked').val();

            //要先判断是否符合要求
            if(username.trim().length < 6){
                //小于6位不通过
                alert("用户名要不低于6位");
            }else if( password.trim().length < 6){
                //小于6位不通过
                alert("密码要不低于6位");
            }else {
                if("管理员"===member){
                    $.ajax({
                        url: "/admin/adminLoginCheck",
                        type: "PUT",
                        data: {
                            username: username,
                            password: password,
                        },
                        success: function (data) {
                            console.log(data);
                            if(data.flag){
                                // alert("成功");
                                window.location = "/admin/index";
                            }else {
                                alert(data.message);
                            }
                        },
                        error: function (e) {
                            alert("error!");
                        }
                    })
                }else if("售货员"===member){
                    $.ajax({
                        url: "/sales/salesLoginCheck",
                        type: "PUT",
                        data: {
                            username: username,
                            password: password,
                        },
                        success: function (data) {
                            console.log(data);
                            if(data.flag){
                                // alert("成功");
                                window.location = "/sales/index";
                            }else {
                                alert(data.message);
                            }
                        },
                        error: function (e) {
                            alert("error!");
                        }
                    })
                }
            }
        });
    })
</script>
</body>
</html>